package com.joinlabs.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.catalina.webresources.WarResourceSet;
import org.springframework.stereotype.Service;

import com.joinlabs.entity.Assess;
import com.joinlabs.entity.Enshrine;
import com.joinlabs.entity.Order;
import com.joinlabs.entity.Orderitem;
import com.joinlabs.entity.ProTypeBean;
import com.joinlabs.entity.Wares;
import com.joinlabs.entity.conditionBean;
import com.joinlabs.mapper.AssessMapper;
import com.joinlabs.mapper.EnshrineMapper;
import com.joinlabs.mapper.OrderMapper;
import com.joinlabs.mapper.OrderitemMapper;
import com.joinlabs.mapper.UserMapper;
import com.joinlabs.mapper.WaresMapper;
import com.joinlabs.service.IProductService;

@Service("WaresService")
public class ProductServiceImpl implements IProductService {

	@Resource
	private WaresMapper waresMapper;
	
	@Resource
	private AssessMapper assessMapper;
	
	@Resource
	private OrderitemMapper orderitemMapper;
	
	@Resource
	private EnshrineMapper enshrineMapper;
	
	@Resource
	private OrderMapper orderMapper;
	
	@Override
	public Wares selectByPrimaryKey(int waresId) {
//		BigDecimal big = new BigDecimal(waresId);
		Wares wares = waresMapper.selectByPrimaryKey(new BigDecimal(waresId));
		
		return wares;
	}
	
	@Override
	public List<Wares> selectBytypeId(int warestypeId) {
//		BigDecimal big = new BigDecimal(waresId);
		List<Wares> wares = waresMapper.selectBytypeId(new BigDecimal(warestypeId));
		
		return wares;
	}

	@Override
	public String selectBytypeName(int warestypeId) {

		String typeName = waresMapper.selectBytypeName(new BigDecimal(warestypeId));
		
		return typeName;
	}

	@Override
	public List<Wares> selectBylikeName(String likeName) {
		
		likeName = "%"+likeName+"%";
		
		List<Wares> wareslist = waresMapper.selectBylikeName(likeName);
		
		return wareslist;
	}

	@Override
	public List<ProTypeBean> selectfyTypeName() {

		List<ProTypeBean> typelist = waresMapper.selectfyTypeName();

		return typelist;
	}

	@Override
	public List<Wares> selectBytypewaresName(conditionBean condtionBean) {

		List<Wares> wareslist = waresMapper.selectBytypewaresName(condtionBean);
		
		return wareslist;
	}

	@Override
	public List<Wares> selectsousuo(String likeName) {
		likeName = "%"+likeName+"%";
		
		List<Wares> wareslist = waresMapper.selectsousuo(likeName);
		
		return wareslist;
	}

	@Override
	public List<Assess> selectBywaresid(BigDecimal waresId) {
		
		List<Assess> asslist = assessMapper.selectBywaresid(waresId);
		
		List<Orderitem> ordlist = orderitemMapper.selectwaresidord(waresId);
		
		return asslist;
	}
	
	@Override
	public List<Orderitem> selectwaresidord(BigDecimal waresId) {
		
		List<Orderitem> ordlist = orderitemMapper.selectwaresidord(waresId);
		
		return ordlist;
	}

	@Override
	public int insertenshrine(Enshrine enshrine) {

		int row = enshrineMapper.insert(enshrine);
		
		return row;
	}

	@Override
	public List<Orderitem> selectByUser(String userId) {

		List<Order> orderlist =  orderMapper.selectByUser(userId);

		System.out.println("-----------orderlist"+orderlist);
		
		List<Orderitem> oitems = new ArrayList<Orderitem>();
		
		for(int i = 0;i < orderlist.size();i++) {
			String ords = orderlist.get(i).getOrderId();
			
			List<Orderitem> orderitems = orderitemMapper.selectItemById(ords);
			
			System.out.println("--------------"+orderitems);
			
			for(int j = 0;j < orderitems.size();j++) {
				oitems.add(orderitems.get(j));
			}
			
		}
		
		System.out.println(oitems);
		
		return oitems;
	}

	@Override
	public Orderitem selectByorderitemid(int orderitemid) {
		
		Orderitem oderitem = orderitemMapper.selectByPrimaryKey(new BigDecimal(orderitemid));
		
		return oderitem;
	}

	@Override
	public Assess selectByorderItemid(int orderitemid) {

		Assess ass = assessMapper.selectByorderItemid(new BigDecimal(orderitemid));
		
		return ass;
	}

	@Override
	public int insertassess(Assess ass) {

		int row = assessMapper.insert(ass);

		return row;
	}

	@Override
	public int selectByprocount(BigDecimal waresId) {

		int row = assessMapper.selectByprocount(waresId);
		
		return row;
	}

	@Override
	public List<Enshrine> selectuserwares(Enshrine enshrine) {

		 List<Enshrine> row = enshrineMapper.selectuserwares(enshrine);

		return row;
	}
	
}
